import { Inject, Controller, Post, Body } from '@midwayjs/core'
import { Context } from '@midwayjs/koa'
import { UserService } from '../service/user.service'
import { DayLogService } from '../service/day_log.service'
import { saveLogReq, getLogByDayReq, getLogListDto, deleteLogByIdReq, loginReq } from '../dto/all-dto'
import { apiResponse } from '../apiResponse'

@Controller('/api')
export class APIController {
  @Inject()
  ctx: Context

  @Inject()
  userService: UserService

  @Inject()
  dayLogService: DayLogService
  @Post('/user/login')
  async login(@Body() body: loginReq) {
    // 147258 4607e782c4d86fd5364d7e4508bb10d9
    if (body.username == 'admin' && body.password == '4607e782c4d86fd5364d7e4508bb10d9') {
      return apiResponse.success({
        username: 'admin',
        password: 'admin',
        role: 'admin',
        roleId: '1',
        permissions: ['*.*.*'],
      })
    } else {
      return apiResponse.error('用户名或密码错误')
    }
  }

  @Post('/role/list')
  async getRoleList(@Body() body: any) {
    const adminList = [
      {
        path: '/dashboard',
        component: '#',
        redirect: '/dashboard/CreateUpdate',
        name: 'Dashboard',
        meta: {
          title: 'router.dashboard',
          icon: 'vi-ant-design:dashboard-filled',
          alwaysShow: false,
        },
        children: [
          // {
          //   path: 'analysis',
          //   component: 'views/Dashboard/Analysis',
          //   name: 'Analysis',
          //   meta: {
          //     title: 'router.analysis',
          //     noCache: true,
          //     affix: false,
          //   },
          // },
          // {
          //   path: 'workplace',
          //   component: 'views/Dashboard/Workplace',
          //   name: 'Workplace',
          //   meta: {
          //     title: 'router.workplace',
          //     noCache: true,
          //     affix: false,
          //   },
          // },
          {
            path: 'CreateUpdate',
            component: 'views/Dashboard/CreateUpdate',
            name: 'CreateUpdate',
            meta: {
              title: '创建日志',
              noCache: true,
              affix: false,
            },
          },
          {
            path: 'List',
            component: 'views/Dashboard/List',
            name: 'List',
            meta: {
              title: '日志列表',
              noCache: true,
              affix: false,
            },
          },
        ],
      },
      {
        path: '/authorization',
        component: '#',
        redirect: '/authorization/user',
        name: 'Authorization',
        meta: {
          title: 'router.authorization',
          icon: 'vi-eos-icons:role-binding',
          alwaysShow: true,
        },
        children: [
          {
            path: 'department',
            component: 'views/Authorization/Department/Department',
            name: 'Department',
            meta: {
              title: 'router.department',
            },
          },
          {
            path: 'user',
            component: 'views/Authorization/User/User',
            name: 'User',
            meta: {
              title: 'router.user',
            },
          },
          {
            path: 'menu',
            component: 'views/Authorization/Menu/Menu',
            name: 'Menu',
            meta: {
              title: 'router.menuManagement',
            },
          },
          {
            path: 'role',
            component: 'views/Authorization/Role/Role',
            name: 'Role',
            meta: {
              title: 'router.role',
            },
          },
        ],
      },
    ]
    return apiResponse.success(adminList)
  }

  @Post('/user/loginOut')
  async loginOut(@Body() body: any) {
    return apiResponse.success()
  }

  @Post('/log/save')
  async saveLog(@Body() body: saveLogReq) {
    return await this.dayLogService.saveLog(body)
  }

  @Post('/get/log/detail/by/day')
  async getLogByDay(@Body() body: getLogByDayReq) {
    return await this.dayLogService.getLogByDay(body)
  }

  @Post('/delete/log/by/id')
  async deleteById(@Body() body: deleteLogByIdReq) {
    return await this.dayLogService.deleteById(body)
  }

  @Post('/log/list')
  async getLogList(@Body() body: getLogListDto) {
    return await this.dayLogService.getLogList(body)
  }
}
